<?php
/**
* Django's templating engine (partial) PHP implementation
* @link http://djangoproject.com Django
* this file is from a webappkit package (kit)
* @link http://webappkit.net
* @package djtpl
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* generic node tag
* use only static methods, unless tag is undefined
*/
class DjTplTagNode extends DjTplNode {

    /**
    * render to string
    * @access public
    * @return string
    */
    function render(&$context) {
        return '<!-- unsupported tag : '.$this->getTagName().' -->'
        .($this->isAtomic()?'':
            $this->renderChildNodes($context));
    }/**/

    /**
    * builds itself from tokens
    * @param djangoTplToken &$selfToken
    * @param array &$nextTokens djangoTplToken
    * @access public
    * @return bool
    */
    function buildFromTokens(&$selfToken, &$nextTokens) {
        //$this->token=&$selfToken;
        $this->tagname=$selfToken->getTagName();
        $this->tagdef=$selfToken->getTagDef();
        // building child nodes
        $this->buildChildNodesFromTokens($nextTokens);
        return true;
    }/**/

    /**
    * return own tag name
    * @access public
    * @return string
    */
    function getTagName() {
        if (isset($this->tagname) and $this->tagname)
            return $this->tagname;
        else
        // class name minus 'DjTplTagNode_'
        return substr(get_class($this),13);
    }

    /**
     * if is block, return block name
     * @access public
     * @return string|false
     */
    function isBlock() {
        return false;
    }

    /**
    * @var string tag name
    */
    //var $tagname;

    /**
    * loops tokens array until ending tag, build child nodes
    *
    * @param array &$tokens
    * @access protected
    * @return bool
    */
    function buildChildNodesFromTokens(&$tokens) {
        //echo $this->getTagName().' building child nodes<br />';
        if ($this->isAtomic())
            return false;
        // expected end tag name ?
        $endtag='end'.$this->getTagName();
        // looping
        $this->childnodes=djtplParser::tokensToNodesUntilTag($tokens,$endtag,$this->template);
        return true;
    }/**/
}
